<?php
namespace Shop\Controller;
use Shop\BaseController;

class IndexController extends BaseController {

    public function index(){
        $uid = session(C('USER_AUTH_KEY'));

        /*获得组信息*/
        $sysUser = M("gm_sys_user",null,DB_GM_CFG);
        $sysNode = M("gm_sys_node",null,DB_GM_CFG);
        $result	= $sysUser
                        ->field('role_id')
                        ->where('id=' . $uid)
                        ->find();

        $userRoleId = intval($result['role_id']);
        $menu_secondary_item = getSecondaryMenu();
        $menu_third_item = getThirdMenu($userRoleId);
        $menu = array();
        foreach($menu_secondary_item as $key=>$value){
            $menu_item = array(
                'title'   => $value['title'],
                'class'   => $value['classname'],
                'items'   => array(),
            );

            //如果三级菜单栏的pid 等于 二级菜单栏的id 则添加到 menu的items内
            foreach($menu_third_item as $k=>$v){
                if($value['id'] == $v['pid'] && $v['is_menu']) {
                    $path = getAllPathMenu($v['path']);
                    $item = array($v['title'], U("{$path}"));
                    array_push($menu_item['items'], $item);
                }
            }
            array_push($menu, $menu_item);
        }





        $smarty=getSmarty();
        $smarty->assign('menus',$menu);
        $smarty->assign('user', session("real_name"));

        $smarty->display('index.html');
    }
}